package com.heima.wemedia.listener;

import com.alibaba.fastjson.JSON;
import com.heima.common.constants.UserConstants;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CreateWmUserListener {

    @Autowired
    private WmUserService wmUserService;

    @KafkaListener(topics = UserConstants.USER_ATTESTATION_SUCCESS_TOPIC)
    public void onMessage(String message){
        if(StringUtils.isNotBlank(message)){
            WmUser wmUser = JSON.parseObject(message, WmUser.class);
            wmUserService.insert(wmUser);
            log.info("用户认证创建自媒体用户成功");
        }
    }

}
